<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: S3aps::FileAdapter</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/s3aps/file_adapter_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/s3aps/file_adapter.rb">lib/s3aps/file_adapter.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-list">#list</a></li>
					
					<li><a href="#method-i-read">#read</a></li>
					
					<li><a href="#method-i-write">#write</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../S3aps/FileAdapter.html">S3aps::FileAdapter</a></li>
				
					<li><a href="../S3aps/Runner.html">S3aps::Runner</a></li>
				
					<li><a href="../S3aps/S3Adapter.html">S3aps::S3Adapter</a></li>
				
					<li><a href="../S3aps/Sync.html">S3aps::Sync</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">S3aps::FileAdapter</h1>

		<div id="description">
			<p>
Reads, writes and lists files on the filesystem.
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(options = {})</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Options:
</p>
<ul>
<li><p>
:path - where the local files are (default is <tt>tmp</tt>)
</p>
</li>
</ul>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/file_adapter.rb, line 9</span>
 9:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
10:       <span class="ruby-ivar">@path</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:path</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;tmp&quot;</span>
11:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="list-method" class="method-detail ">
				<a name="method-i-list"></a>

				<div class="method-heading">
				
					<span class="method-name">list</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
List all the files in the path, recursively
</p>
					

					
					<div class="method-source-code"
						id="list-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/file_adapter.rb, line 14</span>
14:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">list</span>
15:       <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-node">&quot;#{@path}/**/*&quot;</span>).<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">path</span>) }.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
16:         <span class="ruby-identifier">path</span>.<span class="ruby-identifier">sub</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;^#{@path}\/&quot;</span>), <span class="ruby-value str">''</span>
17:       <span class="ruby-keyword kw">end</span>
18:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="read-method" class="method-detail ">
				<a name="method-i-read"></a>

				<div class="method-heading">
				
					<span class="method-name">read</span><span
						class="method-args">(path)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Read the file.
</p>
					

					
					<div class="method-source-code"
						id="read-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/file_adapter.rb, line 38</span>
38:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
39:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">path</span>),<span class="ruby-value str">&quot;rb&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span> <span class="ruby-identifier">io</span>.<span class="ruby-identifier">read</span>}
40:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="write-method" class="method-detail ">
				<a name="method-i-write"></a>

				<div class="method-heading">
				
					<span class="method-name">write</span><span
						class="method-args">(path, value, md5sum = nil)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Write the file. It will always write the file whether it&#8217;s there or
not, unless you supply an <tt>md5sum</tt> in which case it will check
whether it&#8217;s different first.
</p>
					

					
					<div class="method-source-code"
						id="write-source">
<pre>
    <span class="ruby-comment cmt"># File lib/s3aps/file_adapter.rb, line 23</span>
23:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">md5sum</span> = <span class="ruby-keyword kw">nil</span>)
24:                   <span class="ruby-identifier">just_path</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">sub</span> <span class="ruby-regexp re">/\/[^\/]*$/</span>, <span class="ruby-value str">''</span>
25:                   <span class="ruby-identifier">local_md5</span> = <span class="ruby-identifier">md5sum</span>(<span class="ruby-identifier">path</span>)
26:                   <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">local_md5</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">local_md5</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">md5sum</span>
27:                   <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">just_path</span>))
28:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">path</span>), <span class="ruby-value str">'w'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">outfile</span><span class="ruby-operator">|</span> 
29:           <span class="ruby-identifier">outfile</span>.<span class="ruby-identifier">print</span>(<span class="ruby-identifier">value</span>)
30:         }
31:         <span class="ruby-keyword kw">true</span>
32:       <span class="ruby-keyword kw">else</span>
33:         <span class="ruby-keyword kw">false</span>
34:       <span class="ruby-keyword kw">end</span>
35:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

